package controllers

import (
	"cinema/models"

	"github.com/astaxie/beego"
)

type SearchController struct {
	beego.Controller
}

func (this *SearchController) Get() {
	this.TplName = ""
}

// 显示电影信息
func (this *SearchController) Post() {
	FilmId := this.Input().Get("FilmId")
	film, err := models.FilmDetails(FilmId)
	if err != nil {
		beego.Error(err)
		return
	}
	codejson := Message{Code: 0, Data: film, Msg: "显示成功"}

	this.Data["json"] = codejson
	this.ServeJSON()
	this.Redirect("", 302)
	return

}

//显示上映影院信息
func (this *SearchController) GetCinemaInfo() {
	FilmId := this.Input().Get("FilmId")
	seat, err := models.CinemaInfo(FilmId)
	if err != nil {
		beego.Error(err)
		return
	}
	codejson := Message{Code: 0, Data: seat, Msg: "显示成功"}

	this.Data["json"] = codejson
	this.ServeJSON()
	this.Redirect("", 302)
	return
}

//显示订单信息
func (this *SearchController) GetOrderInfo() {
	name, _, flag := checkAccount(this.Ctx)
	if !flag {
		this.Redirect("/login", 302)
		return
	}
	orderInfo, status := models.OrderInfo(name)
	var codejson interface{}
	if status == 0 {
		codejson = Message{Code: 0, Data: orderInfo, Msg: "查询订单成功"}
	} else {
		codejson = Message{Code: 1, Data: orderInfo, Msg: "查询订单失败"}
	}
	this.Data["json"] = codejson
	this.ServeJSON()
	this.Redirect("", 302)
	return
}
